<template>
    <div>
        <table>
            <tr>
                <td>等级编号</td>
                <td>等级</td>
                <td>操作</td>
            </tr>
            <tr v-for="i in grade_data">
                <td> {{i.id}} </td>
                <td>  {{i.grade}} </td>
                <td>
                    <input type="button" value="修改" @click="updagrade(i.id)">
                    <input type="button" value="删除" @click="deletegrade(i.id)">
                </td>
            </tr>
        </table>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            grade_data:[]
        }
    },
    methods:{
        deletegrade(gid){
            let form_data = new FormData()
            form_data.append("gid",gid)
            axios({
                url:"http://127.0.0.1:8000/app01/gradeapi/",
                method:"delete",
                data:form_data
            }).then(res=>{
                console.log(res)
                axios({
                    url:"http://127.0.0.1:8000/app01/gradeapi/",
                    method:"get"
                }).then(res=>{
                    // console.log(res)
                    this.grade_data = res.data
                })
            })
        },
        updagrade(gid){
            this.$router.push({name:'UpdateGrade',params:{"gid":gid}})
        }
    },
    created(){
        axios({
            url:"http://127.0.0.1:8000/app01/gradeapi/",
            method:"get"
        }).then(res=>{
            console.log(res)
            this.grade_data = res.data
        })
    }
}
</script>